package org.example;

public class Test2 {
    //leetcode 198 打家劫舍 https://leetcode.cn/problems/house-robber/description/
    public int rob(int[] nums) {
        int n = nums.length;
        int[][] dp = new int[n+1][2];
        //dp[i][0]表示第i个房子偷时的最高金额，dp[i][1]表示第i个房子不=不偷时候的最高金额
        for (int i = 1; i <= n; i++) {
            dp[i][0] = dp[i-1][1] + nums[i-1];
            dp[i][1] = Math.max(dp[i-1][0],dp[i-1][1]);
        }
        return Math.max(dp[n][0],dp[n][1]);
    }
}
